package net.yambal.android.secretary_alarm.voice;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import net.yambal.android.secretary_alarm.file.VoiceDownloader;
import net.yambal.android.util.ArrayUtil;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;

public class voiceBuilderBase implements IVoiceBuilder{
	public Context _context;
	private SharedPreferences _sharedPreferences;
	private Editor _editor;
	private VoiceDownloader _voice_downloader;
	//private IVoiceBuilderListener _cliant;
	
	//private File _save_to;
	private String _save_dir;
	private String _save_name;
	
	private List<File> _saveed_to;
	
	private Long _alarm_mill;
	private String _user_name;
	
	private String _builded_txt;
	
	public voiceBuilderBase(Context context){
		_sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		_editor = _sharedPreferences.edit();
		_voice_downloader = new VoiceDownloader();
	}
	public voiceBuilderBase(Context context, String save_dir, String save_name, Long alarm_mill, String user_name){
		_context = context.getApplicationContext();
		_sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		_editor = _sharedPreferences.edit();
		_voice_downloader = new VoiceDownloader();
		//_cliant = cliant;
		
		//_save_to = save_to;
		_save_dir = save_dir;
		_save_name = save_name;
		
		_alarm_mill = alarm_mill;
		_user_name = user_name;
	}
	
	public Context getContext(){
		return _context;
	}
	
	public IVoiceBuilder build(){
		_editor.putString(getSharedPreferencesVoiceFileKey(), null);
		_editor.commit();
		_saveed_to = _voice_downloader.download(buldTxt(_alarm_mill, _user_name), _save_dir, _save_name, getSharedPreferencesVoiceFileKey());
		return this;
	}
	
	public String buldTxt(Long alarm_timing_mill, String user_name){
		return null;
	}

	//IVoiceBuilder
	@Override
	public String getSharedPreferencesVoiceFileKey() {
		return null;
	}
	
	@Override
	public String save_to() {
		List<String> res = new ArrayList<String>();
		Log.i("sa", "voiceBuilderBase.save_to("+ getSharedPreferencesVoiceFileKey() +"):" + res);
		Log.i("sa", "voiceBuilderBase.save_to("+ getSharedPreferencesVoiceFileKey() +"):" + _saveed_to);

		while(_saveed_to.size() > 0){
			res.add(_saveed_to.remove(0).getPath());
		}

		return ArrayUtil.ListToCSV(res);
	}
	
	@Override
	public String builded() {
		return _builded_txt;
	}
}
